package tests;

import static org.junit.Assert.*;

import org.junit.Test;

import base.Arc;



public class ArcTest {

	@Test
	public void testContains() {
		// tests for normal (math) space, where angles grow counterclockwise
		// do same tests work for compass space, where angles grow clockwise?
		assertTrue(new Arc(15,0).contains(15));
		assertTrue(new Arc(15,0).contains(16));
		assertTrue(new Arc(15, 359).contains(10) == false);
		
		assertTrue(new Arc(315, 15).contains(16) == false);
		assertTrue(new Arc(315, 15).contains(10));
		assertTrue(new Arc(315, 15).contains(320));
		assertTrue(new Arc(315, 15).contains(0));
		assertTrue(new Arc(315, 15).contains(359));
		
		assertTrue(new Arc(15, 0).contains(10) == false);
		
		assertTrue(new Arc(0,0).contains(0));
		assertTrue(new Arc(0,0).contains(1));
		assertTrue(new Arc(0,0).contains(360));
	}
	
	@Test
	public void testIntersect() {
		Arc a = new Arc(30, 45);
		Arc anotherA = new Arc(30, 45);
		Arc b = new Arc(35, 60);
		Arc all = new Arc(0,0);
		
		assertTrue(a.equals(anotherA));
		assertTrue(a.intersect(a).equals(a));
		assertTrue(a.intersect(b).equals(b.intersect(a)));
		
		Arc c = a.intersect(b);
		assertTrue(c.beginAngle == 35 && c.endAngle == 45);
		
		assertTrue(a.intersect(all).equals(a));
		
		Arc e = new Arc(60,70);
		c = a.intersect(e);
		assertTrue(c == null);
		
		Arc d = new Arc(350,40);
		c = a.intersect(d);
		assertTrue(c.beginAngle == 30 && c.endAngle == 40);
		
		c = d.intersect(e);
		assertTrue(c == null);
	}
	
	@Test
	public void containsTestArc()
	{
		Arc a = new Arc(30, 45);
		Arc b = new Arc(40, 60);
		Arc c = new Arc(20, 70);
		
		assertFalse(a.contains(b));
		assertFalse(b.contains(a));
		
		assertTrue(a.contains(a));
		assertTrue(c.contains(a));
		
		Arc all = new Arc(0,0);
		
		assertTrue(all.contains(all));
		assertTrue(all.contains(a));
		
		assertFalse(a.contains(all));
		
		Arc d = new Arc(350,60);
		assertTrue(all.contains(d));
		assertFalse(d.contains(all));
		
		assertTrue(d.contains(a));
		assertFalse(a.contains(d));
		assertTrue(d.contains(b));
	}
	
	@Test
	public void testOverlap() {
		Arc a = new Arc(30, 45);
		Arc b = new Arc(35, 60);
		Arc all = new Arc(0,0);
		
		
		assertTrue(a.overlaps(a));
		
		assertTrue(a.overlaps(b));
		
		assertTrue(a.overlaps(all));
		
		Arc e = new Arc(60,70);
		assertFalse(a.overlaps(e));
		
		Arc d = new Arc(350,40);
		assertTrue(a.overlaps(d));
		
		assertFalse(d.overlaps(e));
	}
	
	@Test
	public void testGetMiddleAngle() {
		Arc a;
		
		a = new Arc(30,60);
		assertTrue(a.getMiddleAngle() == 45);
		
		a = new Arc(10,350);
		assertTrue(a.getMiddleAngle() == (10.0 + 350.0)/2);
		
		a = new Arc(350,10);
		assertTrue(a.getMiddleAngle() == 0);
		
		a = new Arc(350,5);
		assertTrue(a.getMiddleAngle() == 350 + 15.0/2.0);
		
		a = new Arc(350,20);
		assertTrue(a.getMiddleAngle() == 5);
		
		a = new Arc(0,0);
		assertTrue(a.getMiddleAngle() == 180);
	}
}
